package com.gin.danbooru.factory

import com.gin.danbooru.response.DocumentEntity
import okhttp3.ResponseBody
import org.jsoup.Jsoup
import retrofit2.Converter

/**
 * @author BX-Gin
 * @from 2024/2/27 10:13
 */
class DocumentEntityConverter<T : DocumentEntity>(private val clazz: Class<T>) : Converter<ResponseBody, T> {
    override fun convert(responseBody: ResponseBody): T? {
        val document = Jsoup.parse(responseBody.string())
        val constructors = clazz.constructors
        val instance = constructors[0].newInstance(document)
        return instance as T?
    }
}